package com.neusoft.license.common.res;

import com.neusoft.license.common.constant.RestConstant;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: xlh
 * @Description: 统一返回对象
 * @Date: Create in 16:57 2020/8/24 0024
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RestResponse<T> {

    private Integer code;

    private String msg;

    private T data;

    public RestResponse(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 成功返回调用
     * @return RestResponse
     */
    public RestResponse ok() {
        return new RestResponse(RestConstant.CODE, RestConstant.SUCCESS_MESSAGE);
    }

    /**
     * 返回成功调用并携带参数信息
     * @param data
     * @return
     */
    public RestResponse okWithParameters(T data) {
        return new RestResponse(RestConstant.CODE, RestConstant.SUCCESS_MESSAGE, data);
    }

    /**
     * 返回成功调用并携带返回信息
     * @param msg
     * @return
     */
    public RestResponse okWithMessage(String msg) {
        return new RestResponse(RestConstant.CODE, msg);
    }
}
